import * as types from './mutations-types'

import {
	toDecimal2
} from '@/utils/index.js'
// import {
// 	getWalletInfo
// } from '@/api/user.js'

// 设置导航栏信息
export const setHeaderInfo = function({
	commit
}, data) {
	commit(types.SET_HEADER_INFO, data)
}
//搜索历史
export const setSearchHistory = function({
	commit
}, searchText) {
	let historyList = uni.getStorageSync('searchHistory') || []
	let index = historyList.findIndex((item) => {
		return item == searchText
	})
	index > -1 && (historyList.splice(index, 1))
	historyList.unshift(searchText)
	if (historyList.length > 10) {
		historyList.pop()
	}
	uni.setStorageSync('searchHistory', historyList)
	commit(types.SET_SEARCH_HISTORY, historyList)
}
//清空搜索历史
export const clearSearchHistory = function({
	commit
}) {
	uni.setStorageSync('searchHistory', [])
	commit(types.SET_SEARCH_HISTORY, [])
}

//设置openid unionId 
export const setOUid = function({
	commit
}, data) {
	uni.setStorageSync('ouId', data)
	commit(types.SET_OUID, data)
}

//设置用户信息
export const setUserInfo = function ({commit}, data) {
	console.log(data);
  commit(types.SET_USER_INFO, data)
}

//退出登录
export const logOut = function({
	commit
}) {
	uni.setStorageSync('ouId', '')
	uni.setStorageSync('token', '')
	uni.removeStorageSync('userInfo')

	commit(types.LOG_OUT)
}


// 设置推广位id
export const setPositionIds = function({
	commit
}, data) {
	commit(types.SET_POSITIONIDS, data)
}

// 全局接切板弹框
export const showClipboard = function({
	commit
}, data) {
	commit(types.SHOW_CLIPBOARD, data)
}

export const setLocation = function({
	commit
}, data) {

	uni.setStorageSync('SET_LOCATIONS', data)
	commit(types.SET_LOCATIONS, data)
}

export const setProjectType = function({
	commit
}, data) {
	uni.setStorageSync('projectType', data)
	commit(types.SET_PROJECT_TYPE, data)
}


export const setMyProjectType = function({
	commit
}, data) {

	uni.setStorageSync('MyProjectType', data)
	commit(types.SET_MY_PROJECT_TYPE, data)
}

export const setMyTagType = function({
	commit
}, data) {
	uni.setStorageSync('setMyTagType', data)
	commit(types.SET_TAG_TYPE, data)
}

// 设置当前城市 SET_SELECT_CITY_TYPE
export const setMySelectCityType = function({
	commit
}, data) {
	uni.setStorageSync('SET_SELECT_CITY_TYPE', data)
	commit(types.SET_SELECT_CITY_TYPE, data)
}

export const setMyWallInfo = function({
	commit
}, data) {
	// uni.setStorageSync('projectType',data)
	// getWalletInfo()
	// 	.then(res => {
	// 		if (res.code == '1') {
	// 			var datas = res.data
	// 			var a = parseFloat(datas[0].amount)
	// 			var b = parseFloat(datas[1].amount)
	// 			var money = a
	// 			var reward = b
	// 			// money: 0,
	// 			// reward: 0,
	// 			// allmoney: 0,

	// 			var allmoney = a + b
	// 			console.log(res);
	// 			var myWallInfo = {

	// 				money: toDecimal2(money + ''),
	// 				reward: toDecimal2(reward + ""),
	// 				allmoney: toDecimal2(allmoney + '')
	// 			}
	// 			commit(types.SET_MY_WALLINFO, myWallInfo)
	// 			// this.$tip.toast('密码修改成功,重新登录')
	// 			// this.logout()
	// 		}

	// 	})
	// 	.catch(err => {

	// 	})

}